package com.klangner.go.app.rules;

import java.util.HashSet;
import java.util.Set;

import com.klangner.game.board.Move;

// a location on the goban: can be a stone or just an empty intersection
public class GobanLocation{

	/** x position */
	public int x;
	/** y position */
  public int y;

      //can be EMPTY, BLACK or WHITE
  public int state;

	
    public GobanLocation(int State) {
        state = State;
        liberties_ = new HashSet<GobanLocation>();
    }

    public GobanLocation(GobanLocation location) {
        x = location.x;
        y = location.y;
        state = location.state;

        liberties_ = new HashSet<GobanLocation>();
    }

        //constructor
    public GobanLocation(int X, int Y, int State, BoardModel currentPosition) {
        x = X;
        y = Y;
        state = State;

        liberties_ = new HashSet<GobanLocation>();
    }

        //constructor
    public GobanLocation(Move theMove, BoardModel currentPosition) {
        x = theMove.getX();
        y = theMove.getY();
        state = theMove.getColor();

        liberties_ = new HashSet<GobanLocation>();
    }


        // set the group this stone belongs to
    public void setGroup(StonesGroupOld group) {this.group = group;}

        // set the group this stone belongs to
    public StonesGroupOld getGroup() {return this.group;}


        // overriding Object's comparing method
    public boolean equals(Object anObject) {
            //if (anObject instanceof GobanLocation) {
        GobanLocation currentLocation = (GobanLocation)anObject;
        if ((this.x == currentLocation.x) &&
            (this.y == currentLocation.y))
            return true;
            //}
        return false;
    }

    public String toString() {
        return "(" + x + "," + y + ";" + state + ")";
    }
    
    public void addLiberty( GobanLocation point ) {
        liberties_.add( point );
    }

    public Set<GobanLocation> getLiberties() {
        return liberties_;
    }
    
        // the group this stone belongs to (IF this is a stone)
    private StonesGroupOld group;

        // the list of liberties surrounding this location
    private Set<GobanLocation> liberties_;
}
